/*
 * Czołg.
 */
#include "Tank.h"
#include "Direction.h"
#include "MapManager.h"
Tank::Tank()
{
}

Tank::Tank(BITMAP* bmp) : ATile(bmp)
{
	xSpeed = 1;
	ySpeed = 1;
	counter = 25;
}

void Tank::move(int dir)
{
	printf("%d - ", direction);
	direction = dir;
	printf("%d\n", direction);
	switch(direction)
	{
		case Direction::NORTH :
			y -= ySpeed;
			if(MapManager::getInstance()->tankIntersects(*this))
				y += ySpeed;
			break;
		case Direction::SOUTH :
			y += ySpeed;
			if(MapManager::getInstance()->tankIntersects(*this))
				y -= ySpeed;
			break;
		case Direction::EAST :
			x += xSpeed;
			if(MapManager::getInstance()->tankIntersects(*this))
				x -= xSpeed;
			break;
		case Direction::WEST :
			x -= xSpeed;
			if(MapManager::getInstance()->tankIntersects(*this))
				x += xSpeed;
			break;
	}
}

Bullet * Tank::shoot(BITMAP *img)
{
	if(counter-- <= 0)
	{
		counter = 25;
		return (new Bullet(img, direction, x+(int)getImage()->w/3, y+(int)getImage()->h/3));\
	}
	return NULL;
}

Tank::~Tank()
{
	
}
